import 'package:flutter/material.dart';
import 'package:lyps_music/components/search_input.dart';
import 'package:window_manager/window_manager.dart';

class TopBar extends StatefulWidget {
  const TopBar({super.key});
  @override
  State<StatefulWidget> createState() => _TopBarState();
}

class _TopBarState extends State<TopBar> {
  bool closeActived = false;
  bool minActived = false;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Container(
                width: 200,
                height: 40,
                margin: EdgeInsets.only(left: 20,top: 10),
                decoration: BoxDecoration(
                  color: Colors.black.withOpacity(0.2),
                  borderRadius: BorderRadius.circular(10)
                ),
                child: SearchInput(),
              )
            ],
          ),
          Expanded(
            child: DragToMoveArea(
              child: SizedBox(height: 20),
            ),
          ),
          Row(
            children: [
              MouseRegion(
                onEnter: (event) {
                  setState(() {
                    minActived = true;
                  });
                },
                cursor: SystemMouseCursors.click,
                onExit: (event) {
                  setState(() {
                    minActived = false;
                  });
                },
                child: GestureDetector(
                  onTap: () {
                    windowManager.minimize();
                  },
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 8, vertical: 5),
                    color: minActived ? Colors.black.withOpacity(0.5) : Colors.transparent,
                    child: Icon(
                      Icons.minimize,
                      size: 15,
                      color: minActived ? Colors.white : Colors.black,
                    ),
                  ),
                ),
              ),
              MouseRegion(
                onEnter: (event) {
                  setState(() {
                    closeActived = true;
                  });
                },
                cursor: SystemMouseCursors.click,
                onExit: (event) {
                  setState(() {
                    closeActived = false;
                  });
                },
                child: GestureDetector(
                  onTap: () {
                    windowManager.close();
                  },
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 8, vertical: 5),
                    color: closeActived ? Colors.redAccent : Colors.transparent,
                    child: Icon(
                      Icons.close,
                      size: 15,
                      color: closeActived ? Colors.white : Colors.black,
                    ),
                  ),
                ),
              )
            ],
          ),
        ],
      ),
    );
  }
}
